#include<iostream>
#include<functional>
#include<memory>
#include"Log.hpp"
#include"TcpServer.hpp"
#include"Calculator.hpp"

Calculator calculator; 

void DefaultOnMessage(std::weak_ptr<Connection> conn) 
{
    if(conn.expired()) return ;
    auto connection_ptr = conn.lock();
    std::cout << "上层得到了数据: " << connection_ptr->Inbuffer() << std::endl; 
    std::string response_str = calculator.Handler(connection_ptr->Inbuffer());
    if(response_str.empty()) return ;
    lg(Debug, "%s", response_str.c_str());
    connection_ptr->AppendOutBuffer(response_str);

    auto tcpserver = connection_ptr->_tcp_server_ptr.lock();
    tcpserver->Sender(connection_ptr); 
}

int main()
{
    std::shared_ptr<TcpServer> epoll_svr(new TcpServer(8888, DefaultOnMessage));
    epoll_svr->Init();
    epoll_svr->Loop();

    return ; 
}
